package com.lysj.food.food.controller;

import com.lysj.admin.utils.json.JacksonUtil;
import com.lysj.admin.utils.spring.foundation.base.BaseController;
import com.lysj.admin.utils.web.Resp;
import com.lysj.food.food.domain.DefaultFood;
import com.lysj.food.food.dto.FoodAndCount;
import com.lysj.food.food.dto.FoodAndCountList;
import com.lysj.food.food.service.DefaultFoodService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Created by wtl on 2019-03-25 14:27:56
 * @description 默认下单菜品控制层
 */
@Slf4j
@RestController
@RequestMapping("/food/default_food")
public class DefaultFoodController extends BaseController<DefaultFood> {

    @Resource
    private DefaultFoodService defaultFoodService;

    @Override
    public DefaultFoodService getService() {
        return defaultFoodService;
    }


    @GetMapping("/default_food_list")
    public Resp defaultFoodList(String storeId) {
        return new Resp().success(defaultFoodService.findByStoreId(storeId));
    }

    /**
     * @param storeId       门店id
     * @param foodAndCounts 菜品id和数量json数组
     * @author Created by wtl on 2019/3/26 20:43
     * @Description 批量添加默认菜品
     */
    @PostMapping("/add")
    public Resp add(String storeId, String foodAndCounts) {
        return new Resp().success(defaultFoodService.add(storeId, JacksonUtil.toList(foodAndCounts, FoodAndCount.class)));
    }

}
